package com.lwl.office.webeditor.parser;

import com.lwl.office.webeditor.ParserContext;
import com.lwl.office.webeditor.config.HeaderConfig;
import com.lwl.office.webeditor.style.Style;
import com.lwl.office.webeditor.tools.ConvertUtil;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFStyle;
import org.jsoup.nodes.Element;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;

/**
 * h标签属于特殊的P标签
 */
public class ListNodeParser extends PNodeParser{
    @Override
    public void parser(ParserContext context, Style style) {
        XWPFParagraph paragraph = context.createParagraph();
        String tag = ((Element) getNode()).tagName();
        int level = Integer.parseInt(tag.replace("h",""));
        context.buildHeaderStyle(level);
        CTPPr pPr = paragraph.getCTP().addNewPPr();
        XWPFStyle xwpfStyle = context.getWord().getStyles().getStyleWithName(HeaderConfig.name + level);
        pPr.setPStyle(ConvertUtil.ctsOf(xwpfStyle.getStyleId()));
        super.parser(paragraph,context,style);
    }
}
